﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using WindowsGame1.ItemClasses;

namespace WindowsGame1.SpriteClasses
{
    public class Monster : AnimatedSprite
    {
        float attackRadius;
        bool inCombat = false;
        SpriteBatch combatSpriteBatch;
        int InitialRecharge;
        int Movement;
        int HP;
        int recharge;
        int gold; //Cash the monster has on him
        int exp; //How much you can learn from beating him
        List<BaseItem> items;

        public Monster(Game game, Texture2D texture, List<Animation> animations, int InitialRecharge,
            int Movement, int HP)
            : this(game, texture, animations, InitialRecharge, Movement, HP, 100, 100,null)
        {
        }

        public Monster(Game game, Texture2D texture, List<Animation> animations, int InitialRecharge,
            int Movement, int HP, int gold, int exp)
            : this(game, texture, animations, InitialRecharge, Movement, HP, gold, exp, null)
        {    
        }

        public Monster(Game game, Texture2D texture, List<Animation> animations, int InitialRecharge,
            int Movement, int HP, int gold, int exp, List<BaseItem> items)
            : base(game, texture, animations)
        {
            attackRadius = 80f;
            this.InitialRecharge = InitialRecharge;
            recharge = InitialRecharge;
            this.Movement = Movement;
            this.HP = HP;
            this.exp = exp;
            this.gold = gold;
            this.items = items;
            combatSpriteBatch = (SpriteBatch)game.Services.GetService(typeof(SpriteBatch));
        }

        public int getHP()
        {
            return HP;
        }
        public void getHit()
        {
            HP--;
        }

        public int Recharge
        {
            get { return recharge; }
            set { recharge = value; }
        }

        public void resetRecharge()
        {
            recharge = InitialRecharge;
        }

        public void Follow(int i)
        {
            Random r = new Random();

            int stagger = r.Next(3);

            if (stagger % 3 == 0)
            {


                int l = r.Next(2);
                if (l == 1 && (position.Y + Movement * 3) < 660)
                    position.Y += Movement * 3;
                else if (l == 0 && (position.Y - Movement * 3) > 0)
                    position.Y -= Movement * 3;
                else
                    position.Y += 0;
            }
            else { }
            /*if (30 < i)
                position.Y+= Movement;
            else if (-30 > i)
                position.Y-= Movement;*/
             
        }

        public float AttackRadius
        {
            get { return attackRadius; }
        }

        public bool InCombat
        {
            get { return inCombat; }
            set { inCombat = value; }
        }

        public int Gold
        {
            get { return gold; }
        }

        public int Exp
        {
            get { return exp; }
        }

        public List<BaseItem> Items
        {
            get { return items; }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (InCombat)
            {
                if (0 == recharge)
                    resetRecharge();
                else
                    recharge--;
            }
        }

        public override void Draw(GameTime gameTime)
        {
            if (!inCombat)
            {
                base.Draw(gameTime);
            }
            else
            {
                combatSpriteBatch.Draw(
                texture,
                Position,
                CurrentRectangle,
                Color.White);
            }
        }
    }
}
